package stock;

import javax.persistence.EntityManagerFactory;
import javax.servlet.annotation.ServletSecurity;
import javax.servlet.http.HttpServletRequest;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.orm.hibernate5.HibernateTransactionManager;
import org.springframework.stereotype.Component;

@Component
public class ProjectSession {

	@Autowired
	public EntityManagerFactory entityManagerFactory;

	 
	
	public org.hibernate.Session getSession() { 
		 
		return entityManagerFactory.unwrap(SessionFactory.class).openSession();
	}

	@Bean
	public HibernateTransactionManager gethibernateTransactionManager() {

		HibernateTransactionManager h = new HibernateTransactionManager();
		h.setSessionFactory(entityManagerFactory.unwrap(SessionFactory.class));
		return h;
	};

	 
	
}
